package com.aixin.csopuser.controller;

import com.aixin.common.utils.StringUtils;

import com.aixin.csopequity.domain.EquityLevelDef;
import com.aixin.csopsupplier.domain.ServiceDef;
import com.aixin.csopuser.domain.AxjyOrderDetail;
import com.aixin.csopuser.domain.CustomerDomain;
import com.aixin.csopuser.domain.YjkMembers;
import com.aixin.csopuser.model.CustomerModel;
import com.aixin.csopuser.service.CustomerService;
import com.aixin.csopuser.service.YjkApiService;
import com.aixin.csopuser.utils.ResponseUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api")
@EnableAutoConfiguration
public class PlatformApiController {

    @Autowired
    private YjkApiService apiService;

    @GetMapping("/yjk-members")
    public ResponseEntity<List<YjkMembers>> getYjkMembers(String mobilePhone) {

        List<YjkMembers> members = apiService.findMembers(mobilePhone);
        return ResponseEntity.ok().body(members);
    }

    @GetMapping("/axjy-order-detail/{mobile}")
    public ResponseEntity<List<AxjyOrderDetail>> getAxjyOrderDetail(@PathVariable String mobile) {

        if (StringUtils.isEmpty(mobile)) {
            ResponseEntity.ok(new ArrayList<AxjyOrderDetail>());
        }

        List<AxjyOrderDetail> list = apiService.getOrderDetail(mobile);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 获取客户信息（客户，客户权益，保单，保单权益（服务）
     */
    @GetMapping(value = "/customer-info")
    public ResponseEntity<List<CustomerDomain>> getPageCustomer(CustomerModel customerModel) {
        if(StringUtils.isEmpty(customerModel.getCertID()) )
        {
            return  ResponseEntity.ok().body(new ArrayList<CustomerDomain>());
        }
        if(StringUtils.isEmpty(String.valueOf(customerModel.getCertType())) )
        {
            return  ResponseEntity.ok().body(new ArrayList<CustomerDomain>());
        }
        if(StringUtils.isEmpty(customerModel.getPhoneNumber()))
        {
            return  ResponseEntity.ok().body(new ArrayList<CustomerDomain>());
        }
        if(StringUtils.isEmpty(customerModel.getBirthday()) )
        {
            return  ResponseEntity.ok().body(new ArrayList<CustomerDomain>());
        }
        if(StringUtils.isEmpty(customerModel.getCustName()) )
        {
            return  ResponseEntity.ok().body(new ArrayList<CustomerDomain>());
        }
        if(customerModel.getGender()==null )
        {
            return  ResponseEntity.ok().body(new ArrayList<CustomerDomain>());
        }

        List<CustomerDomain> list = apiService.apiGetCustomer(customerModel);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 获取全部权益级别数据
     * @return
     */
    @GetMapping(value = "/equity-levels")
    public ResponseEntity<List<EquityLevelDef>> getAllEquityLevel() {
        return ResponseEntity.ok().body(apiService.getAllEquityLevel());
    }

    /**
     * 获取全部服务数据
     * @return
     */
    @GetMapping(value = "/services")
    public ResponseEntity<List<ServiceDef>> getAllService() {
        return ResponseEntity.ok().body(apiService.getAllService());
    }
}
